import java.util.Hashtable;
import java.util.Map;

public abstract aspect ProtocoloSingleton{
    
    private Map singletons = new Hashtable();
    
    public interface Singleton{}
    
//    public pointcut protegido();

    Object around() : call((Singleton+).new(..)) {//&& !protegido(){
        Class singleton = thisJoinPoint.getSignature().getDeclaringType();
        System.out.println("singletonClass="+singleton.getSimpleName());
        if(singletons.get(singleton)==null){
            System.out.println("criando o objeto");
            singletons.put(singleton, proceed());
        }
        System.out.println("classe retornada="+singletons.get(singleton));
        return singletons.get(singleton);
    }

    
}
